#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
using namespace std;

class Solution {
public:
    int calculate(string s) {
        stack<string> S;
        s.insert(0,"(");
        s+=')';
        for(int i = 0;i<s.size();++i){
            if(S.empty()&&s[i]!=' '){
                string temp = "";
                S.push(temp+s[i]);
                
            }
            else if(s[i]==' '){
                
            }
            else if(s[i]>='0'&&s[i]<='9'){
                if(S.top()!="+"&&S.top()!="-"&&S.top()!="("){
                    S.top() = S.top()+s[i];
                }
                else{
                    string temp = "";
                    S.push(temp+s[i]);
                }
                
            }
            else if(s[i]==')'){
                int temp = 0;
                while(S.top()!="("){
                    int A = stoi(S.top());
                    S.pop();
                    if(S.top()=="-"){
                        A = -1*A;
                        S.pop();
                    }
                    else if(S.top()=="+"){
                        S.pop();
                    }
                    
                    temp+=A;
                }
                S.pop();
                S.push(to_string(temp));
                
            }
            else{
                
                string temp = "";
                if(s[i]=='('){
                    S.push(temp+s[i]);
                    S.push("+");
                }
                else{
                    S.push(temp+s[i]);
                }
                
            }


        }
        return stoi(S.top());

    }
};

int main(){
    Solution S;
    cout<<S.calculate("-2+1")<<endl;
}